home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / Real / realprefs_old.c < prev    next >
C/C++ Source or Header  |  1997-05-02  |  8KB  |  323 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Miîosîaw Smyk
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include <pragmas/exec_pragmas.h>
  26. #include <pragmas/intuition_pragmas.h>
  27. #include <pragmas/gadtools_pragmas.h>
  28. #include <pragmas/graphics_pragmas.h>
  29. #include <pragmas/utility_pragmas.h>
  30.  
  31. #include <proto/diskfont.h>
  32.  
  33. #include "wfmhcybergfx_key.h"
  34. #include "realprefs.h"
  35.  
  36. extern struct KeyBase *KeyBase;
  37.  
  38. struct Screen         *Scr = NULL;
  39. UBYTE                 *PubScreenName = NULL;
  40. APTR                   VisualInfo = NULL;
  41. struct Window         *RealPrefsWnd = NULL;
  42. struct Gadget         *RealPrefsGList = NULL;
  43. struct IntuiMessage    RealPrefsMsg;
  44. struct Gadget         *RealPrefsGadgets[4];
  45. UWORD                  RealPrefsLeft = 50;
  46. UWORD                  RealPrefsTop = 150;
  47. UWORD                  RealPrefsWidth = 263;
  48. UWORD                  RealPrefsHeight = 49;
  49. UBYTE                 *RealPrefsWdt = (UBYTE *)"wfmhcybergfx_r3d.library";
  50. struct TextAttr       *Font, Attr;
  51. UWORD                  FontX, FontY;
  52. UWORD                  OffX, OffY;
  53. struct TextFont       *RealPrefsFont = NULL;
  54. int public;
  55.  
  56. UBYTE *Gadget000Labels[] = {
  57.     (UBYTE *)"Floyd-Steinberg",
  58.     (UBYTE *)"Ordered 4x4",
  59.     (UBYTE *)"None",
  60.     NULL };
  61.  
  62. UWORD RealPrefsGTypes[] = {
  63.     CYCLE_KIND,
  64.     BUTTON_KIND,
  65.     BUTTON_KIND,
  66.     BUTTON_KIND
  67. };
  68.  
  69. struct NewGadget RealPrefsNGad[] = {
  70.     92, 6, 160, 14, (UBYTE *)"_Dithering", NULL, GD_Gadget00, PLACETEXT_LEFT, NULL, (APTR)Gadget00Clicked,
  71.     10, 30, 76, 14, (UBYTE *)"_Save", NULL, GD_Gadget10, PLACETEXT_IN, NULL, (APTR)Gadget10Clicked,
  72.     176, 30, 76, 14, (UBYTE *)"_Cancel", NULL, GD_Gadget20, PLACETEXT_IN, NULL, (APTR)Gadget20Clicked,
  73.     94, 30, 76, 14, (UBYTE *)"_Use", NULL, GD_Gadget30, PLACETEXT_IN, NULL, (APTR)Gadget30Clicked
  74. };
  75.  
  76. ULONG RealPrefsGTags[] = {
  77.     (GTCY_Labels), (ULONG)&Gadget000Labels[ 0 ], (GT_Underscore), '_', (TAG_DONE),
  78.     (GT_Underscore), '_', (TAG_DONE),
  79.     (GT_Underscore), '_', (TAG_DONE),
  80.     (GT_Underscore), '_', (TAG_DONE)
  81. };
  82.  
  83. static UWORD ComputeX( UWORD value )
  84. {
  85.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  86. }
  87.  
  88. static UWORD ComputeY( UWORD value )
  89. {
  90.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  91. }
  92.  
  93. static void ComputeFont( UWORD width, UWORD height )
  94. {
  95.     Forbid();
  96.     Font = &Attr;
  97.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  98.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  99.     FontX = GfxBase->DefaultFont->tf_XSize;
  100.     Permit();
  101.  
  102.     OffX = Scr->WBorLeft;
  103.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  104.  
  105.     if ( width && height ) {
  106.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  107.             goto UseTopaz;
  108.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  109.             goto UseTopaz;
  110.     }
  111.     return;
  112.  
  113. UseTopaz:
  114.     Font->ta_Name = (STRPTR)"topaz.font";
  115.     FontX = FontY = Font->ta_YSize = 8;
  116. }
  117.  
  118. int SetupScreen(struct Screen *scr)
  119. {
  120.     if(scr)
  121.     {
  122.         Scr = scr;
  123.         public = FALSE;
  124.     }
  125.     else
  126.     {
  127.         public = TRUE;
  128.         if ( ! ( Scr = LockPubScreen( PubScreenName )))
  129.             return( 1L );
  130.         
  131.     }
  132.  
  133.     ComputeFont( 0, 0 );
  134.  
  135.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  136.         return( 2L );
  137.  
  138.     return( 0L );
  139. }
  140.  
  141. void CloseDownScreen( void )
  142. {
  143.     if ( VisualInfo ) {
  144.         FreeVisualInfo( VisualInfo );
  145.         VisualInfo = NULL;
  146.     }
  147.  
  148.     if(Scr && public)
  149.         UnlockPubScreen(NULL, Scr);
  150.  
  151.     Scr = NULL;
  152. }
  153.  
  154. void RealPrefsRender( void )
  155. {
  156.     ComputeFont( RealPrefsWidth, RealPrefsHeight );
  157.  
  158.     DrawBevelBox( RealPrefsWnd->RPort, OffX + ComputeX( 0 ),
  159.                     OffY + ComputeY( 0 ),
  160.                     ComputeX( 263 ),
  161.                     ComputeY( 49 ),
  162.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  163. }
  164.  
  165. int HandleRealPrefsIDCMP( void )
  166. {
  167.     struct IntuiMessage    *m;
  168.     int            (*func)();
  169.     BOOL            running = TRUE;
  170.     ULONG cycle;
  171.  
  172.     WaitPort(RealPrefsWnd->UserPort);
  173.     while( m = GT_GetIMsg( RealPrefsWnd->UserPort )) {
  174.  
  175.         CopyMem(( char * )m, ( char * )&RealPrefsMsg, (long)sizeof( struct IntuiMessage ));
  176.  
  177.         GT_ReplyIMsg( m );
  178.  
  179.         switch ( RealPrefsMsg.Class ) {
  180.  
  181.             case    IDCMP_CHANGEWINDOW:
  182.                 RealPrefsLeft   = RealPrefsWnd->LeftEdge;
  183.                 RealPrefsTop    = RealPrefsWnd->TopEdge;
  184.                 break;
  185.  
  186.             case    IDCMP_REFRESHWINDOW:
  187.                 GT_BeginRefresh( RealPrefsWnd );
  188.                 RealPrefsRender();
  189.                 GT_EndRefresh( RealPrefsWnd, TRUE );
  190.                 break;
  191.  
  192.             case    IDCMP_CLOSEWINDOW:
  193.                 running = RealPrefsCloseWindow();
  194.                 break;
  195.  
  196.             case    IDCMP_GADGETUP:
  197.                 func = ( void * )(( struct Gadget * )RealPrefsMsg.IAddress )->UserData;
  198.                 running = func();
  199.                 break;
  200.  
  201.             case IDCMP_VANILLAKEY:
  202.                 switch(RealPrefsMsg.Code)
  203.                 {
  204.                     case 's':
  205.                     case 'S':
  206.                         running = Gadget10Clicked();
  207.                         break;
  208.  
  209.                     case 'u':
  210.                     case 'U':
  211.                         running = Gadget30Clicked();
  212.                         break;
  213.  
  214.                     case '\x1b':
  215.                     case 'c':
  216.                     case 'C':
  217.                         running = Gadget20Clicked();
  218.                         break;
  219.  
  220.                     case 'd':
  221.                     case 'D':
  222.                         GT_GetGadgetAttrs(RealPrefsGadgets[0], RealPrefsWnd, NULL, GTCY_Active, &cycle);
  223.  
  224.                         if(RealPrefsMsg.Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
  225.                             cycle = cycle == 0 ? 2 : cycle - 1;
  226.                         else
  227.                             cycle = cycle == 2 ? 0 : cycle + 1;
  228.                             
  229.                         GT_SetGadgetAttrs(RealPrefsGadgets[0], RealPrefsWnd, NULL, GTCY_Active, cycle);
  230.  
  231.                         running = Gadget00Clicked();
  232.                         break;
  233.                 }
  234.  
  235.                 break;
  236.         }
  237.     }
  238.     return( running );
  239. }
  240.  
  241. int OpenRealPrefsWindow( void )
  242. {
  243.     struct NewGadget    ng;
  244.     struct Gadget    *g;
  245.     UWORD        lc, tc;
  246.     UWORD        wleft = RealPrefsLeft, wtop = RealPrefsTop, ww, wh;
  247.  
  248.     ComputeFont( RealPrefsWidth, RealPrefsHeight );
  249.  
  250.     ww = ComputeX( RealPrefsWidth );
  251.     wh = ComputeY( RealPrefsHeight );
  252.  
  253.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  254.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  255.  
  256.     if ( ! ( RealPrefsFont = OpenDiskFont( Font )))
  257.         return( 5L );
  258.  
  259.     if ( ! ( g = CreateContext( &RealPrefsGList )))
  260.         return( 1L );
  261.  
  262.     for( lc = 0, tc = 0; lc < RealPrefs_CNT; lc++ ) {
  263.  
  264.         CopyMem((char * )&RealPrefsNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  265.  
  266.         ng.ng_VisualInfo = VisualInfo;
  267.         ng.ng_TextAttr   = Font;
  268.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  269.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  270.         ng.ng_Width      = ComputeX( ng.ng_Width );
  271.         ng.ng_Height     = ComputeY( ng.ng_Height);
  272.  
  273.         RealPrefsGadgets[ lc ] = g = CreateGadgetA((ULONG)RealPrefsGTypes[ lc ], g, &ng, ( struct TagItem * )&RealPrefsGTags[ tc ] );
  274.  
  275.         while( RealPrefsGTags[ tc ] ) tc += 2;
  276.         tc++;
  277.  
  278.         if ( NOT g )
  279.             return( 2L );
  280.     }
  281.  
  282.     GT_SetGadgetAttrs(RealPrefsGadgets[0], RealPrefsWnd, NULL, GTCY_Active, KeyBase->dither_type);
  283.  
  284.     if ( ! ( RealPrefsWnd = OpenWindowTags( NULL,
  285.                 WA_Left,    wleft,
  286.                 WA_Top,        wtop,
  287.                 WA_Width,    ww + OffX + Scr->WBorRight,
  288.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  289.                 WA_IDCMP,    CYCLEIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_CHANGEWINDOW|IDCMP_VANILLAKEY,
  290.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  291.                 WA_Gadgets,    RealPrefsGList,
  292.                 WA_Title,    RealPrefsWdt,
  293.                 WA_ScreenTitle,    "wfmhcybergfx_r3d.library ©1995-97 Miloslaw Smyk  (thorgal@dedal.man.szczecin.pl)",
  294.                 WA_PubScreen,    Scr,
  295.                 TAG_DONE )))
  296.     return( 4L );
  297.  
  298.     GT_RefreshWindow( RealPrefsWnd, NULL );
  299.  
  300.     RealPrefsRender();
  301.  
  302.     return( 0L );
  303. }
  304.  
  305. void CloseRealPrefsWindow( void )
  306. {
  307.     if ( RealPrefsWnd        ) {
  308.         CloseWindow( RealPrefsWnd );
  309.         RealPrefsWnd = NULL;
  310.     }
  311.  
  312.     if ( RealPrefsGList      ) {
  313.         FreeGadgets( RealPrefsGList );
  314.         RealPrefsGList = NULL;
  315.     }
  316.  
  317.     if ( RealPrefsFont ) {
  318.         CloseFont( RealPrefsFont );
  319.         RealPrefsFont = NULL;
  320.     }
  321. }
  322.  
  323.